<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use DateTimeInterface;

class PackageContentModel extends Model
{
    use HasFactory;

    protected $table = 'package_content';
    protected $dateFormat = 'U';//这个时间字段被为被格式化为UNIX 时间戳的形式存储

    //toArray 时间转换问题
    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }

    //套餐内容列表
    static public function getContentInfo($data)
    {
        return SELF::select(
                        'a.id',
                        'b.class_name as materiel_first_class_name',
                        'b.class_no as materiel_first_class_no',
                        'c.class_name as materiel_class_name',
                        'c.class_no as materiel_class_no',
                        'd.materiel_name',
                        'd.type_name',
                        'd.materiel_img',
                        'd.materiel_thumbnail_img',
                        'd.materiel_no',
                        'a.storage_id',
                        'e.storage_name',
                        'e.storage_address',
                        'a.storage_manage_id',
                        'a.package_id',
                        'a.num',
                        'f.in_storage_num',
                        'f.delete_flag'
                    )
                    ->from('package_content as a')
                    ->leftJoin('materiel_class as b', 'b.id', '=', 'a.materiel_first_class_id')
                    ->leftJoin('materiel_class as c', 'c.id', '=', 'a.materiel_class_id')
                    ->leftJoin('materiel_type as d', 'd.id', '=', 'a.type_id')
                    ->leftJoin('storage as e', 'e.id', '=', 'a.storage_id')
                    ->leftJoin('storage_manage as f', 'f.id', '=', 'a.storage_manage_id')
                    ->where('package_id', $data['id'])
                    ->where('a.delete_flag', 0)
                    ->paginate($data['pageSize'],['*'], '',$data['currentPage']);
    }
}
